package com.gulimall.search.controller;

import com.guli.common.utils.R;
import com.guli.common.vo.SkuEsModel;
import com.gulimall.search.service.SearchServiceImpl;
import com.gulimall.search.vo.SearchParam;
import com.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.List;

/**
 * @author 武者
 * @title: SearchController
 * @projectName gulimall-zhuan5
 * @description:
 * @date 2022/1/7 17:03
 */
@Controller
public class SearchController {

    @Autowired
    SearchServiceImpl searchService;



    @PostMapping("/upsku")
    @ResponseBody
    public R upSku(@RequestBody List<SkuEsModel> skuEsModels) throws IOException {

        return searchService.addAll(skuEsModels);
    }

    @RequestMapping(value = {"/","search.html"})
    public  String  search(SearchParam searchParam,Model model) throws IOException {

        SearchResult searchResult=searchService.search(searchParam);

        model.addAttribute("result",searchResult);
        return "search.html";
    }

}
